package logic

import "gddgame.cc/galaxy/utils"

type Config struct {
	// cluster
	Node    string `json:"node"`
	Address string `json:"address"`

	// store
	Database string `json:"database" galaxy:"option"`

	// deploy
	WorkPath   string `json:"work_path" galaxy:"option"`
	LogPath    string `json:"log_path" galaxy:"option"`
	MaxRecover int    `json:"max_recover" galaxy:"option"`
	LogFormat  string `json:"log_format" galaxy:"option"`
}

func (config *Config) Init() error {
	if config.Database == "" {
		config.Database = "/etc/neutron/neutron.db"
	}
	if config.WorkPath == "" {
		config.WorkPath = "/tmp/neutron_work/"
	}
	if config.LogPath == "" {
		config.LogPath = "/var/log/"
	}
	if config.LogFormat == "" {
		config.LogFormat = "%Y-%M-%D.log"
	}
	if err := utils.Mkdir(config.WorkPath); err != nil {
		return err
	}
	if config.MaxRecover == 0 {
		config.MaxRecover = 5
	}
	return nil
}
